#!/bin/sh
# PCP QA Test No. 1328
# Exercise pmcd.zoneinfo
#
# Copyright (c) 2021 Ken McDonell.  All Rights Reserved.
#

if [ $# -eq 0 ]
then
    seq=`basename $0`
    echo "QA output created by $seq"
else
    # use $seq from caller, unless not set
    [ -n "$seq" ] || seq=`basename $0`
    echo "QA output created by `basename $0` $*"
fi

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

_cleanup()
{
    cd $here
    $sudo rm -rf $tmp $tmp.*
}

status=0	# success is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

# real QA test starts here
zoneinfo=`pminfo -f pmcd.zoneinfo | sed -n -e '/^ *value /{
s///
s/"//g
p
}'`
if [ -z "$zoneinfo" ]
then
    echo "no value for pmcd.zoneinfo ..."
    pminfo -f pmcd.zoneinfo
fi

# need to be careful of clock ticking over, so try up to 3 times with
# 100 msec delay between each try
#
for try in 1 2 3
do
    raw=`date '+%y/%m/%d %H:%M:%S'`
    cooked=`TZ=$zoneinfo date '+%y/%m/%d %H:%M:%S'`
    echo "raw=$raw" >>$seq_full
    echo "cooked=$cooked (TZ=$zoneinfo)" >>$seq_full
    if [ "$raw" = "$cooked" ]
    then
	echo "Dates match."
	# success
	exit
    fi
    pmsleep 0.1
done

echo "Failed to match $raw vs (TZ=$zoneinfo) $cooked"
exit
